package model

import "gpt-api/framework/db"

type Area struct {
	db.BaseModel
	Code         string `json:"code" gorm:"column:code;type:varchar(255);default:'';comment:code"`
	Name         string `json:"name" gorm:"column:name;type:varchar(255);default:'';comment:name"`
	Citycode     string `json:"citycode" gorm:"column:citycode;type:varchar(255);default:'';comment:citycode"`
	Provincecode string `json:"provincecode" gorm:"column:provincecode;type:varchar(255);default:'';comment:provincecode"`
}

func (m Area) TableName() string {
	return "area"
}

// 根据citycode查询所有区
func (m Area) GetAreaByCityCode(database *db.DB, citycode string) ([]Area, error) {
	var areas []Area
	err := database.Model(&Area{}).Where("citycode = ?", citycode).Find(&areas).Error
	return areas, err
}
